<?php
namespace app\admin\controller;
use think\Db;
use app\admin\model\CommonModel;
use think\Session;
use think\Cookie;

/**
 * By：wl
 * Date：2018.11
 * Function:左边公共导航，主页
 */

class Index extends Base
{
    public function index()
    {
        $uid = Cookie::get('admin_userid_tp5');
        $groupid = Session::get('admin_userinfo_tp5'.$uid);
        $group_info = DB::table('admingroup')->where('id',$groupid['groupid'])->find();
        $power = $group_info['power'];

        $power_arr = explode(",", $power);
    	$list = Db::query('select * from admin_menu where pid=0 and status = 1 order by rank desc');  
        
        foreach ($list as $k => $v) {
            if(!in_array($v['id'], $power_arr)){//去除没有权限的内容
                unset($list[$k]);
            }else{
                $id = $v['id'];
                $list[$k]['data'] = Db::query("select * from admin_menu where pid=$id and status = 1 order by rank desc");
                foreach ($list[$k]['data'] as $kk => $vv) {
                    if(!in_array($vv['id'], $power_arr)){//去除没有权限的内容
                        unset($list[$k]['data'][$kk]);
                    }else{
                       if($vv['controller'] == ''){
                            $ids = $vv['id'];
                            $list[$k]['data'][$kk]['data2'] =  Db::query("select * from admin_menu where pid=$ids and status = 1 order by rank desc");
                            foreach ($list[$k]['data'][$kk]['data2'] as $kkk => $vvv) {
                                if(!in_array($vvv['id'], $power_arr)){//去除没有权限的内容
                                    unset($list[$k]['data'][$kk]['data2'][$kkk]);
                                }
                            }
                        } 
                    }
                }
            }
        }
    
        
        $this->assign("list",$list);
    	return view();
    }

    public function welcome()
    {

        return view();
    }
}
